<template>
  <div class="app-container">
    <el-form ref="placeCodeForm" v-loading="formLoading" :rules="rules" :model="form" label-position="top">
      <el-row type="flex" :gutter="20">
        <el-col :span="24">
        </el-col>
      </el-row>

      <el-row type="flex" :gutter="20">
        <el-col :span="24">
          <el-form-item :label="form.state ? contentText2 : contentText" prop="content" >
            <el-input type="textarea" v-model="form.content"  :rows="5"/>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>

<script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import {bakGetMajorByIdApi, editMajorApi} from "@/api/school";
import {addHelpApi, getWorkGoApi} from "@/api/QuestionnaireInvestigation";
export default {
  components: { Editor, Toolbar },
  name: 'PlaceCodeDetail',
  data(){
    return{
      editor: null,
      dialogVisible: false,
      contentText: '帮扶内容',
      contentText2: '就业去向',
      form: {
        id: null,
        content:'',
        userId: '',
        state: false
      },
      rules: {
        content: [{ required: true, trigger: 'blur', message: '请输入内容' }],
      },
      formLoading: false,
    }
  },
  props:['id','closeDialog','state'],
  methods:{

    submit(){
      this.$refs.placeCodeForm.validate(valid => {
        if (valid) {
          const loading=this.$loading({
            text:'提交中'
          })
          if(this.form.id==null)
          {
            this.form.id = 0;
          }
          this.form.userId = this.id
          const form=JSON.parse(JSON.stringify(this.form));
          form.state = (this.form.state) ? 2 : 1;
          addHelpApi(form).then((res)=>{
            this.$message.success('保存成功');
            this.closeDialog(3);
          }).catch(()=>{
            this.$message.error('保存失败');
          }).finally(()=>{
            loading.close();
          })
        } else {
          return false
        }
      })
    },
    getWorkGo()
    {
      this.form.userId = this.id
      const form=JSON.parse(JSON.stringify(this.form));
      form.state = (this.form.state) ? 2 : 1;
      getWorkGoApi(form).then((res)=>{
        if(res)
        {
          this.form.id = res.id
          this.form.content = res.content
          this.form.userId = res.userId
        }

      })

    }
  },
  watch: {

  },
  mounted(e) {
    this.form.state = this.state
    this.getWorkGo()
  },

}
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #c5c5c5;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;

}
.w-e-bar.w-e-bar-show.w-e-toolbar{
  border: 1px solid;
}
.w-e-scroll{
  border: 1px solid;
}
</style>
<style scoped>
/*
*让select撑开
*/
.el-select,.el-cascader{
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed #c5c5c5;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;

}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
